﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Zvezda.FSO2.DB;

namespace FSO.Reports
{
    public partial class UserControlOrganizationSelector : UserControl
    {
        public UserControlOrganizationSelector()
        {
            InitializeComponent();
        }
        public bool IsNull
        {
            get
            {
                bool bReturn = true;
                if (radCheckBoxOrgIsNull.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On
                    && _SelectedOrganization != null)
                {
                    bReturn = false;
                }
                 return bReturn;
            }
        }
        /// <summary>
        /// Обрабатывает изменения состояния переключателя выбора значения
        /// </summary>
        private void radCheckBoxOrgIsNull_ToggleStateChanged(object sender, Telerik.WinControls.UI.StateChangedEventArgs args)
        {
            if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
            {
                radButtonSelectOrg.Enabled = true;
                radLabelOrgName.BackColor = Color.White;
                radLabelOrgName.Cursor = Cursors.Hand;
            }
            else
            {
                radButtonSelectOrg.Enabled = false;
                radLabelOrgName.BackColor = Color.WhiteSmoke;
                radLabelOrgName.Cursor = Cursors.Default;
            }
        }

        private DataSetFSO.NSI_ORGANIZATIONRow _SelectedOrganization = null;
        public DataSetFSO.NSI_ORGANIZATIONRow SelectedRow
        {
            get
            {
                return _SelectedOrganization;
            }
        }

        private void radButtonSelectOrg_Click(object sender, EventArgs e)
        {
            if (radCheckBoxOrgIsNull.ToggleState != Telerik.WinControls.Enumerations.ToggleState.On)
            {
                return;
            }
            DialogFormSelectObject dlgFrmSelectObject = new DialogFormSelectObject(ObjctTypeEnum.ORGANIZATION);
            if (dlgFrmSelectObject.ShowDialog() == DialogResult.OK)
            {
                _SelectedOrganization = dlgFrmSelectObject.SelectedRow as DataSetFSO.NSI_ORGANIZATIONRow;
                radLabelOrgName.Text = _SelectedOrganization.SHORT_NAME;
            }
        }
    }
}
